package com.daxue.lcm.api.grpc.model;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @author daxue0929
 * @date 2022/10/9
 */

@Data
@Accessors(chain = true)
@NoArgsConstructor(staticName = "newInstance")
@Slf4j
public class DynamicResourceConfig {

    public static final String DYNAMIC_RESOURCE_CONFIG = "DYNAMIC_RESOURCE_CONFIG";

    private String id;
    private Date createdOn;
    private Date modifiedOn;
    private String tenantId;
    private String code;
    private String name;
    private String description;
    private Map<String, Object> config; // config for usage
    private DynamicResourceType resourceType;
//    private DynamicResourceInfo resourceInfo;
//    private ModelStatus status;

    public Map<String, Object> getConfig() {
        return Optional.ofNullable(config).orElseGet(() -> config = new HashMap<>());
    }

    public DynamicResourceConfig addConfig(String key, Object value) {
        getConfig().put(key, value);
        return this;
    }
}
